package com.wgq.uitest.exp2;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;

import com.wgq.uitest.MainActivity;
import com.wgq.uitest.R;

import java.util.Timer;
import java.util.TimerTask;

public class Frame extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_frame);

        Button btn1 = (Button) findViewById(R.id.quit);

        //返回
        btn1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(Frame.this, MainActivity.class);
                startActivity(intent);
            }
        });

        final ImageView imageView = (ImageView) findViewById(R.id.imageView);
        final ImageView imageView2 = (ImageView) findViewById(R.id.imageView2);
        final ImageView imageView3 = (ImageView) findViewById(R.id.imageView3);
        final ImageView imageView4 = (ImageView) findViewById(R.id.imageView4);
        final ImageView imageView5 = (ImageView) findViewById(R.id.imageView5);

        final Handler mHandler = new Handler();

        /*//第五张图片的消失和显示
        Runnable r = new Runnable() {
            @Override
            public void run() {
                imageView5.setVisibility(View.INVISIBLE);
                mHandler.postDelayed(this, 5000);
            }
        };
        Runnable r2 = new Runnable() {
            @Override
            public void run() {
                imageView5.setVisibility(View.VISIBLE);
                mHandler.postDelayed(this, 5000);
            }
        };

        //第四张图片的消失和显示
        Runnable r3 = new Runnable() {
            @Override
            public void run() {
                imageView4.setVisibility(View.INVISIBLE);
                mHandler.postDelayed(this, 5000);
            }
        };
        Runnable r4 = new Runnable() {
            @Override
            public void run() {
                imageView4.setVisibility(View.VISIBLE);
                mHandler.postDelayed(this, 5000);
            }
        };

        //第三张图片的消失和显示
        Runnable r5 = new Runnable() {
            @Override
            public void run() {
                imageView3.setVisibility(View.INVISIBLE);
                mHandler.postDelayed(this, 5000);
            }
        };
        Runnable r6 = new Runnable() {
            @Override
            public void run() {
                imageView3.setVisibility(View.VISIBLE);
                mHandler.postDelayed(this, 5000);
            }
        };

        //第二张图片的消失和显示
        Runnable r7 = new Runnable() {
            @Override
            public void run() {
                imageView2.setVisibility(View.INVISIBLE);
                mHandler.postDelayed(this, 5000);
            }
        };
        Runnable r8 = new Runnable() {
            @Override
            public void run() {
                imageView2.setVisibility(View.VISIBLE);
                mHandler.postDelayed(this, 5000);
            }
        };

        //第一张图片的消失和显示
        Runnable r9 = new Runnable() {
            @Override
            public void run() {
                imageView.setVisibility(View.INVISIBLE);
                mHandler.postDelayed(this, 5000);
            }
        };
        Runnable r10 = new Runnable() {
            @Override
            public void run() {
                imageView.setVisibility(View.VISIBLE);
                mHandler.postDelayed(this, 5000);
            }
        };

        //延时运行，五张图片轮换展示
        mHandler.postDelayed(r, 1000);
        mHandler.postDelayed(r2, 5000);
        mHandler.postDelayed(r3, 2000);
        mHandler.postDelayed(r4, 6000);
        mHandler.postDelayed(r5, 3000);
        mHandler.postDelayed(r6, 7000);
        mHandler.postDelayed(r7, 4000);
        mHandler.postDelayed(r8, 8000);
        mHandler.postDelayed(r9, 5000);
        mHandler.postDelayed(r10, 9000);*/
        Timer timer = new Timer();
        TimerTask task = new TimerTask() {
            @Override
            public void run() {
                imageView5.setVisibility(View.INVISIBLE);
            }
        };

        TimerTask task2 = new TimerTask() {
            @Override
            public void run() {
                imageView4.setVisibility(View.INVISIBLE);
            }
        };

        TimerTask task3 = new TimerTask() {
            @Override
            public void run() {
                imageView3.setVisibility(View.INVISIBLE);
            }
        };

        TimerTask task4 = new TimerTask() {
            @Override
            public void run() {
                imageView2.setVisibility(View.INVISIBLE);
            }
        };

        TimerTask task5 = new TimerTask() {
            @Override
            public void run() {
                imageView.setVisibility(View.INVISIBLE);
            }
        };

        timer.schedule(task,1000, 5000);
        timer.schedule(task2,2000, 5000);
        timer.schedule(task3,3000, 5000);
        timer.schedule(task4,4000, 5000);
        timer.schedule(task5,5000, 5000);

    }
}
